package com.zhuiyun.pm.client.bidding.service.impl;

import com.zhuiyun.pm.client.bidding.entity.ClientRunningWater;
import com.zhuiyun.pm.client.bidding.mapper.ClientRunningwaterMapper;
import com.zhuiyun.pm.client.bidding.service.ClientRunningWaterService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

@Service
public class ClientRunningWaterServiceImpl implements ClientRunningWaterService {
    @Resource
    ClientRunningwaterMapper clientRunningwaterMapper;
    //总收入
    @Override
    public int sum(int a) {
        List<Integer> sum = clientRunningwaterMapper.sum();
        for(int i=0;i<sum.size();i++){
            int b = sum.get(i);
            a=a+b;
        }
        return a;
    }
    //总支出
    @Override
    public int sumz(int aa) {
        List<Integer> sum2 = clientRunningwaterMapper.sumup();
        for(int t=0;t<sum2.size();t++){
            int c = sum2.get(t);
            aa = c+aa;
        }
        return aa;
    }
    //全查
    @Override
    public List<ClientRunningWater> findAll(){
      int a = 0;
      int aa = 0;
      List<ClientRunningWater> lista = clientRunningwaterMapper.selectAll();
        for (ClientRunningWater clientRunningWater : lista) {
            clientRunningWater.setSum(sum(a));
            clientRunningWater.setSumz(sumz(aa));
        }
        return lista;
    }
    //分页查询
    @Override
    public List<ClientRunningWater> page(int page,int size) {
        int a=0;
        int aa=0;
        page = (page-1)* size;
        List<ClientRunningWater> lista = clientRunningwaterMapper.listpage(page,size);
        int total = clientRunningwaterMapper.total();
        for (ClientRunningWater clientRunningWater : lista) {
            clientRunningWater.setTotal(total);
            clientRunningWater.setSum(sum(a));
            clientRunningWater.setSumz(sumz(aa));
        }
        return lista;
    }
    //生成流水号
    @Override
    public String ls(Integer id) {
        ClientRunningWater tt = clientRunningwaterMapper.selectByPrimaryKey(id);
        int num = (int)(Math.random()*10000);
        String ls = "LS"+id+ LocalDate.now()+num;
        return ls;
    }

    @Override
    public ClientRunningWater lsbyid(ClientRunningWater clientRunningWater) {
        clientRunningwaterMapper.add(clientRunningWater);
        ClientRunningWater ls =clientRunningwaterMapper.lsbyid();
        Integer id = ls.getId();
        String lsh =ls(id);
        ClientRunningWater clientRunningWater11 = new ClientRunningWater();
        clientRunningWater11.setId(id);
        clientRunningWater11.setSerialNumber(lsh);
        clientRunningwaterMapper.updateserialNumber(clientRunningWater11);
        return null;
    }




}
